export default {
  namespaced:true,
  state:() =>({
    address:JSON.parse(uni.getStorageSync('address')||'{}'),
    token: uni.getStorageSync('toke') || '',
    userInfo:JSON.parse(uni.getStorageSync('userInfo')||'{}'),
    redirectInfo:null //重定向的对象
  }),
  // state:{
  //   add:'中国'
  // },
  mutations:{
    //更新收货地址
    updateAddress(state,address){
      state.address = address
      this.commit('m_user/saveAddressStorage')
    },
    //对收货地址数据持久化
    saveAddressStorage(state){
      uni.setStorageSync('address',JSON.stringify(state.address))
    },
    // 对用户信息数据持久化
    saveUserInfoStorage(state){
      uni.setStorageSync('userInfo',JSON.stringify(state.userInfo))
    },
    // 获取用户信息
    updateUserInfo(state,userInfo){
      state.userInfo = userInfo
      this.commit('m_user/saveUserInfoStorage')
    },
    // 更新token
    updateToken(state,tok){
      state.token = tok
      this.commit('m_user/saveTokenStorage')
    },
    //持久化token
    saveTokenStorage(state){
      uni.setStorageSync('toke',state.token)
    },
    updateRedirectInfo(state, info){
      state.redirectInfo = info
      console.log(state.redirectInfo);
    }
  },
  actions:{},
  getters:{
    addstr(state){
      if(!state.address.provinceName) return ''
      return state.address.provinceName + state.address.cityName + state.address.countyName + state.address.detailInfo
    }
  }
}